package com.wizz.trade.information.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.information.dto.page.StaPageDto;
import com.wizz.trade.information.entity.Sta;
import com.wizz.trade.information.mapper.StaMapper;
import com.wizz.trade.information.service.StaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.common.PageVo;
import com.wizz.trade.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 仓储协议表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class StaServiceImpl extends ServiceImpl<StaMapper, Sta> implements StaService {

    @Resource
    private StaMapper staMapper;

    @Override
    public void addSta(Sta sta) {
        staMapper.insert(sta);
    }

    @Override
    public void updateSta(Sta sta) {
        staMapper.updateById(sta);
    }

    @Override
    public void deleteSta(Integer id) {
        staMapper.deleteById(id);
    }

    @Override
    public PageVo<Sta> getPage(StaPageDto staPageDto) {
        LambdaQueryWrapper<Sta> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(!Objects.isNull(staPageDto.getOurcompany()),Sta::getOurcompany, staPageDto.getOurcompany());
        queryWrapper.eq(!Objects.isNull(staPageDto.getStorage()), Sta::getStorage, staPageDto.getStorage());
        IPage<Sta> page = staMapper.selectPage(PageUtil.initPage(staPageDto), queryWrapper);
        return new PageVo<>(page);
    }

    @Override
    public List<Sta> getAll() {
        return staMapper.selectList(null);
    }

}
